/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mini_game_fx;

import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.animation.TimelineBuilder;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.util.Duration;

/**
 *
 * @author Joshua
 */
public class MiniGameLooper {
    
    
    public MiniGameLooper(MiniGameFx game){
        final Duration oneFrameAmt = Duration.millis(1000 / game.getFrameRate());
            final KeyFrame oneFrame = new KeyFrame(oneFrameAmt, (new MiniGameLoopEventHandler(game))); // oneFrame

            // sets the game world's game loop (Timeline)
            setGameLoop(TimelineBuilder.create()
                    .cycleCount(Animation.INDEFINITE)
                    .keyFrames(oneFrame)
                    .build() );
    }
    protected void setGameLoop(Timeline gameLoop) {
            MiniGameFx.setGameLoop(gameLoop);// = gameLoop;
        }
}
